﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.LightSwitch;
namespace LightSwitchApplication
{
    public partial class Supply
    {
        partial void Tag_Compute(ref string result)
        {
            // Set result to the desired field value
            if(this.Drug != null)
                result = this.Vendor + " (" + this.ShippingDays + "-days shipping)";
        }

        partial void Drug_Validate(EntityValidationResultsBuilder results)
        {
            // results.AddPropertyError("<Error-Message>");
            if (this.Drug != null && this.Vendor != null)
            {
                var dupes = from supply in this.Vendor.Supplies
                            where supply.Drug != null && supply.Drug.Id == this.Drug.Id &&
                                supply.ShippingDays == this.ShippingDays && supply != this
                            select supply;
                if (dupes.Any())
                    results.AddPropertyError("Duplicates: Supply is identified by vendor, drug and shipping days.");
            }
        }

        partial void Supply_Created()
        {
            this.WholesalePrice = 0.01m;
        }
    }
}
